package com.bw.inspection.adapter

import android.os.Build
import androidx.annotation.RequiresApi
import androidx.databinding.DataBindingUtil
import com.bw.inspection.R
import com.bw.inspection.databinding.ItemTaskBinding
import com.bw.inspection.entity.NoInspenctionEntityItem
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class TaskAdapter: BaseQuickAdapter<NoInspenctionEntityItem, BaseViewHolder>(R.layout.item_task) {
    lateinit var binding: ItemTaskBinding
    override fun onItemViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        super.onItemViewHolderCreated(viewHolder, viewType)
        DataBindingUtil.bind<ItemTaskBinding>(viewHolder.itemView)
    }
    @RequiresApi(Build.VERSION_CODES.M)
    override fun convert(helper: BaseViewHolder, item: NoInspenctionEntityItem) {
        binding=DataBindingUtil.getBinding<ItemTaskBinding>(helper.itemView)!!
        binding.bean=item

        when(item.patrolStatus){
            "0"->
                binding.taskType.apply {
                    setText("未巡检")
                    setBackgroundResource(R.drawable.shape_zhanyong)
                    setTextColor(context.getColor(com.bw.resource.R.color.blue))
                }
            "1"->
                binding.taskType.apply {
                    setText("巡检中")
                    setBackgroundResource(R.drawable.shape_weihu)
                    setTextColor(context.getColor(com.bw.resource.R.color.orange))
                }
            "2"->
                binding.taskType.apply {
                    setText("已完成")
                    setBackgroundResource(R.drawable.shape_status)
                    setTextColor(context.getColor(com.bw.resource.R.color.green))
                }
            else->{
                binding.taskType.apply {
                    setText("已作废")
                    setBackgroundResource(R.drawable.shape_solid_lightgray)
                    setTextColor(context.getColor(com.bw.resource.R.color.darkgray))
                }
            }
        }
    }
}